package com.hyz.controller;

import com.hyz.pojo.ResponseResult;
import com.hyz.pojo.repositoryManager.GetAssetImportsResponse;
import com.hyz.pojo.repositoryManager.GetAssetLogByAssetIdResponse;
import com.hyz.pojo.repositoryManager.UpdateAssetImportsRequest;
import com.hyz.service.RepositoryManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author HGD
 * @date 2022/10/4 0:19
 */
@Api("仓库管理员")
@RestController
@RequestMapping("/repositoryManager")
public class RepositoryManagerController {
    @Autowired
    private RepositoryManagerService service;

    @ApiOperation("通过仓库管理员id获取入库申请")
    @ApiResponse(code = 200, message = "成功", response = ResponseResult.class)
    @PostMapping("/getAssetImports")
    public ResponseResult<List<GetAssetImportsResponse>> getAssetImports() {
        return service.getAssetImports();
    }

    @ApiOperation("资产入库审批，返回未分库资产")
    @ApiParam("批量入库审批")
    @ApiResponse(code = 200, message = "成功", response = ResponseResult.class)
    @PostMapping("/updateAssetImports")
    public ResponseResult<List<GetAssetImportsResponse>> batchUpdateAssetImports(@RequestBody UpdateAssetImportsRequest request) {
        if (service.batchUpdateAssetImports(request).getData()) {
            return service.getAssetImports();
        }
        return new ResponseResult<>(500, "失败");
    }

    @ApiOperation("通过资产id获取资产历史列表")
    @ApiParam("资产id")
    @ApiResponse(code = 200, message = "成功", response = ResponseResult.class)
    @PostMapping("/getAssetImportsByAssetId")
    public ResponseResult<List<GetAssetLogByAssetIdResponse>> getAssetLogsByAssetId(@RequestBody Long assetId) {
//        return null;
        return service.getAssetLogsByAssetId(assetId);
    }
}
